/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GameLogic;

import Algorithm.KDTree;
import Algorithm.Pathfinding;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.Map;
import java.util.TreeSet;

/**
 *
 * @author Ix
 */
public class TowerAura implements Comparable<TowerAura> {
    
    public final static double MAX_RANGE = 10;
    public double Range;
    public String name;
    public TBuff b;
    
    
    public TowerAura(String name, double range, TBuff b)
    {
        this.b = b;
        this.name = name;
        this.Range = range;
    }
    
    @Override
    public int compareTo(TowerAura m) {
        return name.compareTo(m.name);
    }
    @Override
    public boolean equals(Object m) {
        if(m.getClass() != TowerAura.class)
            return false;
        return name.equals(((TowerAura)m).name);
    }
    @Override
    public int hashCode() {
        return name.hashCode();
    }
    
    public static void UpdateAuras(Tower t, KDTree k)
    {
        ArrayList<Tower> tList = k.GetNearbyTowers(t.getCenter(), MAX_RANGE);
        tList.remove(t);
        TreeSet<TBuff> oAuras = new TreeSet<TBuff>();
        for(Map.Entry<TBuff, TBuff> e : t.Buffs.entrySet())
                oAuras.add(e.getKey());
        if(tList != null && tList.size() > 0)
        {
            for(Tower tt : tList)
            {
                if(tt.type.tAura != null && 
                Pathfinding.GetDist2(t.getCenter(), tt.getCenter()) <= tt.type.tAura.Range * tt.type.tAura.Range)
                {
                    oAuras.remove(tt.type.tAura.b);
                    tt.type.tAura.b.Apply(t);
                }
            }
        }
        for(TBuff b : oAuras)
            b.Remove(t);
    }
}
